<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of SaveToFile
 *  
 * @author Implement <hdjahs@qq.com>
 */
class SaveToFileByImg {

    private $obj;

    public function __construct($obj) {
        $this->obj = $obj;
    }

    public function save() {
        if ($this->obj->img) {
            $tool = Tool::getIns();
            $data = $tool->http_get_img($this->obj->img);
            $imgPath = $this->obj->imgPath . $this->obj->key . '.jpg';
            if ($data && !file_exists($imgPath)) {
                file_put_contents($imgPath, $data);
                $filePath = $this->obj->tmpPath . md5($imgPath) . '.txt';
                file_put_contents($filePath, 1);
            }
        }
    }

}
